package hk.ust.cse.comp4981;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

public class Ngrams {
	static List<String> san_ngrams = new ArrayList<String>();
	static List<String> ny_ngrams = new ArrayList<String>();

	public static String ngrams(String text, int n) {
		String[] parts = text.split(" ");
		String grams = "";
		// System.out.println(parts.length);
		for (int i = 0; i < parts.length - n + 1; i++) {
			StringBuilder concat = new StringBuilder(parts[i]);
			for (int k = 1; k < n; k++) {
				if (k > 0)
					concat.append(" ");
				concat.append(parts[i + k]);
			}
			grams = grams + ", " + concat.toString();
		}
		return grams;
	}

	public Ngrams() {
		super();
	}

	public static void generateNyNgrams() throws IOException {
		// For New York's tweets
		for (int k = 0; k < Twokenize.ny_toks.size(); k++) {
			// get tokens and no.of tokens in one tweet
			String getTokens = Twokenize.ny_toks.get(k);
			String[] split = getTokens.split(",");
			int no_of_tokens = split.length;
			// get tokens without commas separating
			String text = "";
			for (int j = 0; j < no_of_tokens; j++) {
				text = text + split[j];
			}
			String result = "";
			// generate ngrams
			if (no_of_tokens == 1) { // uni-gram, just print the token
				ny_ngrams.add(getTokens);
			} else {
				// we only generate ngrams with max. n=5
				for (int i = 2; i <= 5; i++) {
					result = result + ngrams(text, i);
				}
				ny_ngrams.add(getTokens + result);
			}
		}
	}

	public static void generateSanNgrams() throws IOException {
		// For New York's tweets
		for (int k = 0; k < Twokenize.san_toks.size(); k++) {
			// get tokens and no.of tokens in one tweet
			String getTokens = Twokenize.san_toks.get(k);
			String[] split = getTokens.split(",");
			int no_of_tokens = split.length;
			// get tokens without commas separating
			String text = "";
			for (int j = 0; j < no_of_tokens; j++) {
				text = text + split[j];
			}
			String result = "";
			// generate ngrams
			if (no_of_tokens == 1) { // uni-gram, just print the token
				san_ngrams.add(getTokens);
			} else {
				// we only generate ngrams with max. n=5
				for (int i = 2; i <= 5; i++) {
					result = result + ngrams(text, i);
				}
				san_ngrams.add(getTokens + result);
			}
		}
	}

}